<template>
  <div>
    <TopNav title="我的关注" />
    <div class="followList">
      <div class="item" v-for="user in followList" :key="user.id">
        <img
          v-if="user.head_img"
          :src="$axios.defaults.baseURL + user.head_img"
          alt=""
          class="avatar"
        />
        <img v-else src="@/assets/default.png" alt="" class="avatar" />
        <div class="Info">
          <div class="name">{{ user.nickname }}</div>
          <div class="date">2019-10-10</div>
        </div>
        <div class="cancelBtn" @click="unfollow(user.id)">取消关注</div>
      </div>
    </div>
  </div>
</template>

<script>
import TopNav from "../../components/TopNav";
export default {
  data() {
    return {
      followList: [],
    };
  },
  components: {
    TopNav,
  },
  created() {
    this.reloadPage();
  },
  methods: {
    reloadPage() {
      this.$axios({
        url: "/user_follows",
      }).then((res) => {
        console.log(res.data);
        //   因为帐号没有关注的新闻，要手动添加
        this.followList = res.data.data;
      });
    },
    unfollow(id) {
      this.$axios({
        url: "/user_unfollow/" + id,
      }).then((res) => {
        console.log(res.data);
        this.reloadPage();
      });
    },
  },
};
</script>

<style lang="less" scoped>
.item {
  display: flex;
  align-items: center;
  padding: 20/360 * 100vw;
  border-bottom: 1px solid #ddd;
  .avatar {
    widows: 40/360 * 100vw;
    height: 40/360 * 100vw;
    border-radius: 50%;
    object-fit: cover;
  }
  .Info {
    flex-grow: 1;
    padding-left: 14/360 * 100vw;
    .name {
      font-size: 16/360 * 100vw;
      color: #333;
      font-weight: bold;
    }
    .date {
      font-size: 12/360 * 100vw;
      color: #888;
    }
  }
  .cancelBtn {
    height: 30/360 * 100vw;
    line-height: 30/360 * 100vw;
    font-size: 12/360 * 100vw;
    padding: 0 10/360 * 100vw;
    background-color: #e1e1e1;
    border-radius: 14/360 * 100vw;
  }
}
</style>